//
//  ProductDetailImage.m
//  FloatClouds
//
//  Created by 黄威 on 16/9/13.
//  Copyright © 2016年 黄威. All rights reserved.
//

#import "ProductDetailImage.h"
#import "BaseCollectionView.h"
#import "TAMacro.h"
#import "ProductDetailImage.h"
#import "ProductImageCell.h"
#import "UIImageView+WebCache.h"
#import "ProductDetailImageCell.h"

@interface ProductDetailImage ()<UICollectionViewDelegate ,UICollectionViewDataSource>
@property (nonatomic,retain) BaseCollectionView *collectionView;
@property (nonatomic, retain) NSMutableDictionary *dic;
@property (nonatomic, assign) BOOL flag;
@property (nonatomic, strong) UILabel *labelOfTitle;


@end

@implementation ProductDetailImage

- (void)viewDidLoad{
    _flag = NO;
     self.automaticallyAdjustsScrollViewInsets = NO;
    [self createNavigation];
    [self createCollectionView];
    //[self createLabel];
   
}
- (void)createNavigation{
    
    //设置navigation相关属性
    
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:18.0 / 255 green:86.0 / 255 blue:138.0 / 255 alpha:1]];
    
    NSDictionary *attributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil];
    
    [self.navigationController.navigationBar setTitleTextAttributes:attributes];
    self.navigationItem.title = @"烟品细节图片";
    
    
}

- (void)createLabel{

    self.labelOfTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, self.view.bounds.size.height *0.9, self.view.bounds.size.width , self.view.bounds.size.height * 0.1)];

    [self.view addSubview:_labelOfTitle];
    
    _labelOfTitle.backgroundColor = [UIColor yellowColor];


}




- (void)createCollectionView{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    
    //*设置item大小/
    layout.itemSize = CGSizeMake((SCREEN_SIZE_WIDTH_ME) , (SCREEN_SIZE_HEIGTH_ME));
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 200;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collectionView = [[BaseCollectionView alloc]initWithFrame:CGRectMake(0 , 0, SCREEN_SIZE_WIDTH_ME , SCREEN_SIZE_HEIGTH_ME) collectionViewLayout:layout];
    
    
    self.collectionView.bounces = NO;
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.pagingEnabled = YES;
    
    self.collectionView.backgroundColor = [UIColor colorWithRed:249 green:249 blue:249 alpha:1];
    [self.view addSubview:self.collectionView];
    self.collectionView.backgroundColor = [UIColor blackColor];
    [self.collectionView registerClass:[ProductDetailImageCell class] forCellWithReuseIdentifier:@"Cell"];
    

}

- (void)viewWillDisappear:(BOOL)animated{

    [super viewWillDisappear:animated];
    
   

}

- (void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];
    
    [self.collectionView scrollToItemAtIndexPath:self.indexPath atScrollPosition:UICollectionViewScrollPositionNone
                                        animated:NO];

 



}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
   
  
    
    ProductDetailImageCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    
    
    cell.backgroundColor = [UIColor blackColor];
    
    NSArray *arrayOfSection = self.arrayOfListPhoto[indexPath.section];
    
    self.dic = arrayOfSection[indexPath.row];
    
    
    
    NSURL *url = [NSURL URLWithString:self.dic[@"big"]];
  
    [cell.imageView sd_setImageWithURL:url];
    
    cell.imageView.transform = CGAffineTransformMakeScale(1, 1 );
   
    cell.imageView.frame = CGRectMake(0, self.view.bounds.size.height * 0.3, self.view.bounds.size.width, self.view.bounds.size.height * 0.4);
 

    return cell;
    
    
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 8;
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  
    
    NSArray *arrayOfSection = self.arrayOfListPhoto[section];
    
    return arrayOfSection.count;
    
}





@end
